export const getUpdateManger = () => {
    // #ifdef APP-PLUS
    plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
        uni.downloadFile({
            url: `https://s.snmi.cn/utils/mapp?version=${widgetInfo.version}&name=${widgetInfo.name}&versionCode=${widgetInfo.versionCode}&appid=${plus.runtime.appid}`,
            sslVerify: false,
            success: downloadResult => {
                uni.showLoading({
                    title: "更新中..."
                });
                if (downloadResult.statusCode === 200) {
                    uni.hideLoading();
                    uni.saveFile({
                        tempFilePath: downloadResult.tempFilePath,
                        success: res => {
                            let savedFilePath = res.savedFilePath;
                            console.log("保存路径", savedFilePath);
                            // #ifdef APP-PLUS
                            plus.runtime.install(
                                savedFilePath,
                                {
                                    force: true
                                },
                                function() {
                                    console.log("导入成功---");
                                    plus.runtime.restart();
                                },
                                function(e) {
                                    console.log("导入失败");
                                }
                            );
                            // #endif
                        }
                    });
                    uni.hideLoading();
                }
            },
            complete: () => {
                uni.hideLoading();
            },
            fail: err => console.log("下载错误")
        });
    });
    // #endif
};
